<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
	  <home></home>
	  
  </div>
  <template id="Home">
	  <div>
		  Home组件
      <child1></child1>
      <hr>
      <child2></child2>
	  </div>
  </template>
 
  <script src="./vue.js"></script>
  <script>
    // 创建一个eventBus 
   const bus = new Vue();
	  // 头部组件
	 const Child1 = {
	
		template:`
			<div>
				子组件1
				<button @click="triggerEvent">向兄弟开炮</button>
			</div>
		`,
		data () {
			return {
        msg: '我是子组件1的数据'
			}
		},
    methods: {
      triggerEvent(){
        bus.$emit('biubiubiu',this.msg)
      }
    }
	 }
   const Child2 = {
      template:`
        <div>
          子组件2
          {{msg}}
        </div>
      `,
      data () {
        return {
          msg: ''
        }
      },
      mounted () {
        bus.$on('biubiubiu',(msg)=>{
          alert('我收到了');
          this.msg = msg;
        })
      }
    }
    const Home = {
      template: '#Home',
      components: {
        Child1,
        Child2
      },
      data () {
        return {
          msg: 'aa'
        }
      },
      methods: {
        receive(msg){
          alert('over over 收到了一个数据时'+msg)
          this.msg = msg
        }
      }
    }
	Vue.component('Home',Home)
	
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>